HotKeySet("q","suspend")

Global $startC1[2] = [75,379] ;coord for start/resume game - top left
Global $startC2[2] = [368,427] ;coord for start/resume game - bottom right

mainLoop()

func mainLoop()
   while 1
	  Sleep(2000) ;sleep for a static amount of time (so you can get everything into position after starting script)
	  makeGame() ;make game
	  ;invitePlayer()
	  waitForPlayer()
	  leaveGame()
   wend
EndFunc

func makeGame()
   Sleep(Random(4000,6000,1)) ;sleep for a wihle in the lobby
   $x = Random($startC1[0], $startC2[0], 1) ;grab a random x coordinate from the "start/resume game" bounds
   $y = Random($startC1[1], $startC2[1], 1) ;grab a random y coordinate from the "start/resume game" bounds
   MouseMove($x,$y,8)
   MouseClick("left")
   Sleep(Random(7000,7800)) ;sleep for a while to account for game start delay
EndFunc 

func invitePlayer()
   send("o")
   sleep(random(200,300,1))
   MouseMove(1330,350,8)
   MouseClick("right")
   sleep(random(300,400,1))
   MouseMove(1400,456,8)
   MouseClick("left")
   sleep(random(300,400,1))
   send("o")
   sleep(random(300,400,1))
EndFunc

func waitForPlayer()
   $coord = PixelSearch(8,15,40,75,0xFFFFFF,0)
   while @error
	  sleep(random(1000,1500,1))
	  $coord = PixelSearch(8,15,40,75,0xFFFFFF,0)
   wend
EndFunc

func leaveGame()
   Sleep(Random(500,600)) ;sleep for a minute
   Send("{ESC}") ;depress escape
   MouseMove(839 + random(-2,2,1),562 + random(-2,2,1),8)
   MouseClick("left")
   Sleep(Random(300,400)) ;sleep for a minute
   MouseMove(730,615,8)
   MouseClick("left")
   Sleep(Random(1000,1500)) ;exit game delay
EndFunc

func suspend()
   Sleep(25000)
EndFunc